
function dynamic() {

    $('#product>.info').on('click', 'li', function () {
        // console.log(this)
        let id = ($(this).prop('class'))
        location.href = "./detail.html?id:" + id
    })

    $('.container').find('.more0').click(function () {
        location.href = "./more0.html"
    })

    $('.container').find('.more1').click(function () {
        location.href = "./more1.html"
    })

    $('.container').find('.more2').click(function () {
        location.href = "./more2.html"
    })

    $('.container').find('.more3').click(function () {
        location.href = "./more3.html"
    })

    $('.container').find('.more4').click(function () {
        location.href = "./more1.html"
    })

    $('.container').find('.more5').click(function () {
        location.href = "./more5.html"
    })

    $('.container').find('.more6').click(function () {
        location.href = "./more0.html"
    })
    
    $('.container').find('.more7').click(function () {
        $('.container').find('.more7').nextAll().slideToggle(200)
    })

    $('.container').find('.more8').click(function () {
        location.href = "./more8.html"
    })
    
    $('.container').find('.more9').click(function () {
        location.href = "./more0.html"
    })

    $('.container').find('.more10').click(function () {
        location.href = "./more10.html"
    })

    $('.container').find('.more11').click(function () {
        location.href = "./more11.html"
    })
}

function apply() {
    let container = document.querySelector('.container')
    let more7 = document.querySelector('.more7')
    let el = ''
    let i = 0

    fetch('http://chst.vip:1234/api/getindexmenu')
        .then(body => body.json())
        .then(res => {
            //console.log(res.result)
            res.result.forEach(item => {
                let regExp = /([^"]+)/g
                //console.log(item)
                let r = item.img.match(regExp);
                el += `<div class="more${i++}">         
                <img src="http://chst.vip:8081/mmb/${r[1]}"/>
                <p>${item.name}</p>
                </div>`

            })
            container.innerHTML = el
        })

    //超值折扣推荐

    let info = document.querySelector('#product>.info')
    let el2 = ""
    let l = 0

    fetch('http://chst.vip:1234/api/getmoneyctrl')
        .then(body => body.json())
        .then(res => {
            //console.log(res)
            res.result.forEach(item => {
                let regExp = /(?<=imgurl=)[^'"]*/;
                let r = item.productImg2.match(regExp);

                el2 += `<li class='${l++}'>
                <a class="clearfix">
                <div class="img fl">
                <img src="${r}" width="100" alt="">
                </div>
                <div class="infoR">
                <div class="title">
                <h4>${item.productName}</h4>
                <span>${item.productPinkage}</span>
                </div>
                <div class="other">
                <span class="mall fl">
                ${item.productFrom}|${item.productTime}
                </span>
                <em class="fr">
                <span>${item.productComCount}</span>
                </em>
                </div>
                </div>
                </a>
                </li>     `
            })
            info.innerHTML = el2;
            dynamic()
        })
}

apply()
